from django.core.mail import send_mail
from tfpp.action.action import Action, MetaAction

class MetaMail(MetaAction):
    def get_properties(self):
        return ('from_email', 'to', 'cc', 'subject', 'message')
    
    def get_clazz(self):
        return Mail

class Mail(Action):
    def action(self):
        super(MetaMail, self).action()
        send_mail(self.data['subject'], 
                  self.data['message'], 
                  self.data['from_email'],
                  [self.data['to'], self.data['cc']], 
                   fail_silently=True)

    def as_text(self):
        result = "send_mail("
        result += "To:%s, " % self.data['to']
        result += "Cc:%s, " % self.data['cc']
        result += "Subject:%s, " % self.data['subject']
        result += "Message:\n%s)" % self.data['message']
        return result

    def as_html(self):
        result = "<i>send_mail</i>("
        result += "<b>To</b>:%s, " % self.data['to']
        result += "<b>Cc</b>:%s, " % self.data['cc']
        result += "<b>Subject</b>:%s, " % self.data['subject']
        result += "<b>Message</b>:\n%s)" % self.data['message']
        return result
